#ifndef LOADAUDIO_H
#define LOADAUDIO_H

#include <QObject>
#include <QThread>
#include <QIODevice>
#include <QAudioOutput>
#include <QMutex>

class LoadAudio : public QThread
{
    Q_OBJECT
public:
    explicit LoadAudio(QObject *parent = nullptr);
    ~LoadAudio();

    void stopImmediately();

    void startPlay();

    void stopPlay();

public slots:
    void onSetVolumn(int);

signals:
    void audiooutputerror(QString);

    void speaker(QString);

private:
    QAudioOutput* m_audioOutput;
    QIODevice* m_outputDevice;
    QMutex m_deviceLock;

    volatile bool m_isRun;
    QMutex m_lock;

    void run() override;

    QString errorString();

private slots:
    void onHandleStateChanged(QAudio::State);

    void onClearQueue();
};

#endif // LOADAUDIO_H
